package com.tanjie.blackbean.orm.generate;

import cn.hutool.core.util.StrUtil;

import java.util.ResourceBundle;

/**
 * 配置文件访问器
 *
 * @author tanjie
 * @date 2021/9/3
 */
public class ConfigAccessor {

    public static GenerationConfig loadDbInfo(String type) {
        if (StrUtil.isBlank(type)) {
            type = "test";
        }
        ResourceBundle resource = ResourceBundle.getBundle("config/generate_" + type);
        String url = resource.getString("url");
        String userName = resource.getString("userName");
        String password = resource.getString("password");
        String tables = resource.getString("tables");
        String author = resource.getString("author");
        String parentPackage = resource.getString("parentPackage");
        String moduleName = resource.getString("moduleName");
        String templatesDir = resource.getString("templatesDir");
        return GenerationConfig.builder()
                .url(url)
                .userName(userName)
                .password(password)
                .tables(tables.split(","))
                .author(author)
                .parentPackage(parentPackage)
                .modelName(moduleName)
                .templatesDir(templatesDir)
                .removePrefix(resource.getString("removePrefix"))
                .build();
    }

}
